import axios from 'axios'
import request from './request';

import { ref } from 'vue'

// 每一个用户项的类型
type UserItem={accountNonExpired:boolean
    accountNonLocked:boolean
    createTime: string
    credentialsNonExpired:boolean
    id: number
    isDel: boolean
    name: string
    password: string
    phone: string
    portrait: string
    regIp: string|null
    satatus: "ENABLE"|"DISABLE"
    updateTime: string
}

type Common<T>={
    code: string
    data: T
    mesg: string
    time: string
}
export type QueryResult ={
    current:number
    hitCount: boolean
    optimizeCountSql: boolean
    orders: any[],pages: number
    records: UserItem[]
    searchCount: boolean
    size: number
    total: number
}
export type QueryCondition = Partial<{
  currentPage: number
  pagesize: number
  phone: string
  userId: number
  startCreateTime: string
  endCreateTime: string
}>



export const queryCondition = ref<QueryCondition>({})

export const queriedResult = ref<Partial<QueryResult>>({
  current: 0,
  hitCount: false,
  optimizeCountSql: false,
  orders: [],
  pages: 0,
  records: [],
  searchCount: false,
  size: 0,
  total: 0
})

//获取用户列表信息
export const getUserPages = (queryCondition: QueryCondition = {}) => {
  return request<Common<QueryResult>>({
    method: 'POST',
    url: '/system/user/',
    data: queryCondition,
    
  })
}

export const queryUsers = async (params:QueryCondition={}) => {
    Object.assign(queryCondition.value,params)
    const {data} = await getUserPages(queryCondition.value)
    if(data.code ==="000000"){
        queriedResult.value = data.data
    }
        else{
            console.log("查询失败");
            
        }
}
